use tauri::{AppHandle, SystemTray, CustomMenuItem, SystemTrayMenu, SystemTrayEvent};
 
// 托盘菜单
pub fn menu() -> SystemTray {
    let tray_menu = SystemTrayMenu::new()
        .add_item(CustomMenuItem::new("quit".to_string(), "Quit")); // 退出
 
    // 设置在右键单击系统托盘时显示菜单
    SystemTray::new().with_menu(tray_menu)
}
 
// 菜单事件
pub fn handler(_app: &AppHandle, event: SystemTrayEvent) {
    // 匹配点击事件
    match event {
        // 根据菜单 id 进行事件匹配
        SystemTrayEvent::MenuItemClick { id, .. } => match id.as_str() {
            "quit" => {
                std::process::exit(0);
            }
            _ => {}
        },
        _ => {}
    }
}